<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        :before-open="beforeOpen"
        v-model="form"
        v-bind="bindVal"
        v-on="onEvent"
        :page.sync="page"
        :permission="permissionList">
        <template slot="menuLeft">
          <el-upload
                  class="upload-inline"
                  action=""
                  :show-file-list="false"
                  accept=".xls,.xlsx"
                  :http-request="handleImport">
                  <el-button type="primary" size="small">导入</el-button>
          </el-upload>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import baseCrud from '@/mixins/base-crud'
import {saveBatch} from '@/api/support/swpmdeviceoperationcodeforline'
import store from '@/store'
export default {
  name: 'swpmdeviceoperationcodeforline',
  mixins: [baseCrud('support/swpmdeviceoperationcodeforline')],
  data() {
    return {
        form: {},
    }
  },
  computed: {
    permissionList() {
      return {
        addBtn: this.vaildData(this.permissions.support_sw_pm_device_operation_code_add, false),
        delBtn: this.vaildData(this.permissions.support_sw_pm_device_operation_code_del, false),
        editBtn: this.vaildData(this.permissions.support_sw_pm_device_operation_code_edit, false)
      };
    }
  },
  methods: {
    beforeOpen(done, type){
      if(type == 'add'){
        setTimeout(()=>{
          this.form.lineCode = store.getters.userInfo.lineCode;
        }, 0)
      }
      done()
    },
    handleImport(item){
      let file = item.file
      let param = new FormData()
      param.append('file',file)
      saveBatch(param).then(() => {
        this.$notify({
          title: '成功',
          message: '导入成功',
          type: 'success',
          duration: 2000
        })
        this.getList(this.page)
      })
    },
  }
}
</script>
